import collections
class Solution(object):
    def findJudge(self, n, trust):
        """
        :type n: int
        :type trust: List[List[int]]
        :rtype: int
        """
        if n == 1:
            return 1
        t = collections.defaultdict(int)
        dt = collections.defaultdict(int)
        for k in trust:
            t[k[0]] += 1
            dt[k[1]] += 1
        for key in dt:
            if dt[key] == n - 1 and not t[key]:
                return key
        return -1